window.onload=function (){
        const { createEditor, createToolbar } = window.wangEditor

        const editorConfig = {
            placeholder: 'Type here...',
            onChange(editor) {
              const html = editor.getHtml()
              console.log('editor content', html)
              // 也可以同步到 <textarea>
            }
        }

        const editor = createEditor({
            selector: '#editor-container',
            html: '<p><br></p>',
            config: editorConfig,
            mode: 'default', // or 'simple'
        })

        const toolbarConfig = {}

        const toolbar = createToolbar({
            editor,
            selector: '#toolbar-container',
            config: toolbarConfig,
            mode: 'default', // or 'simple'
})
        $("#submit-btn").click(function(event) {
        // 阻止按钮的默认行为
        event.preventDefault();

        let title = $("input[name='title']").val();
        let category = $("#category-select").val();
        let content =editor.getHtml();
        if (!content.trim()) {
    alert('内容字段不能为空，请输入博客内容！');
    return;
}
        let csrfmiddlewaretoken = $("input[name='csrfmiddlewaretoken']").val();$
.ajax({
            url: '/pub_blog', // 确保这里的 URL 正确
            method: 'POST',
            data: {
                title: title,
                category: category,
                content: content,
                csrfmiddlewaretoken: csrfmiddlewaretoken
            },
            success: function (result) {
                if(result['code']==200){
                    let blog_id=result['data']['blog_id']
                    window.location='/detail/'+blog_id
                }
                else {
                    alert(result['message'])
                }

            },
            error: function (error) {
                console.log(error);
                // 在这里添加发布博客失败后的处理逻辑
            }
        });
    });
}